<?php

class SGBD {
    
    protected $prepare;
    
    public function __construct(Prepare $prepare) {
        $this->setPrepare($prepare);
    }
    
    public function getPrepare(){
        return $this->prepare;
    }
    public function setPrepare($prepare){
        $this->prepare = $prepare;
    }
    
    public function loadSpecificInfo(){
        $eis = $this->getPrepare()->getSpecificInfo();
        foreach($eis as $si => $value){
            $set = 'set' . ucfirst($si);
            if(method_exists($this, $set)){
                $this->$set($value);
            }
        }
    }
    
    protected function getDNS() { ; }
    
    public function getConnection ($onlyDNS = false) {
       try{
            $dns = $this->getDNS();
            $con = null;
            if($onlyDNS){
                $con = new PDO($dns);
            } else {    
                $prepare = $this->getPrepare();
                $con = new PDO($dns, $prepare->getUser(), $prepare->getPassword());
            }
            return $con;
        } catch (PDOException $e){
            return false;
        }
    } 
    
}

?>
